<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>项目-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<link rel="stylesheet" href="__PUBLIC__/mobile/css/dropload.css">
</head>
<body style="background: #f3f3f3;">
<div class="header" style="line-height:0">
	<a href="__APP__/Mobile/Index/index" class="back_btn"></a>
	<a href="javascript:;" class="header_txt_btn add_btn_new"></a>
    <a href="javascript:;" class="header_txt_btn project_search"></a>
</div>
<div class="content">
    <div class="project_list">
        <ul>
			<foreach name="result" item="vo">
            <li>
				<a href="__APP__/Mobile/Crm/project_situation/id/{$vo['project_id']}">
                    <div class="time">{$vo['project_num']}<span>|</span>{$vo['add_date']}<span>|</span><if condition="$vo['stage'] neq ''">{:get_project_stage($vo['stage'])}</if></div>
                    <div class="name">{$vo['name']}</div>
                    <div class="user"><span>项目负责人：<if condition="$vo['leader'] neq ''">{:get_userName($vo['leader'])}</if></span></div>
                </a>
            </li>
			</foreach>
        </ul>
    </div>
</div>
<!-- 弹框 -->
<div class="search_fix">
    <div class="search_header">
        <a class="back_btn" href="javascript:;"></a>
        <input class="project_search_inp" type="text" value="{$keyword}" placeholder="输入搜索内容…">
        <a href="javascript:;" class="header_txt_btn jd_up">搜索</a>
    </div>
    <div class="form_item">
        <div class="form_item_tit">
            搜索推荐
        </div>
        <div class="form_item_box search_btn_box">
			<if condition="$result_t eq ''">暂无相关内容</if>
			<foreach name="result_t" item="vo">
            <a href="__APP__/Mobile/Crm/project_list/keyword/{$vo['keyword']}">{:msubstr($vo['keyword'],0,6,'utf-8',false)}</a>
			</foreach>
        </div>
        <div class="form_item_tit">
            搜索历史
        </div>
        <div class="form_item_box search_list_box">
            <if condition="$result_l eq ''">
                <p style="padding:7px 0">暂无相关内容</p>
            <else />
                <ul>
                    <foreach name="result_l" item="vo">
                    <li><a href="__APP__/Mobile/Crm/project_list/keyword/{$vo['keyword']}">{$vo['keyword']}</a></li>
                    </foreach>
                </ul>
                <div class="clear">清空搜索历史</div>
            </if>
        </div>
    </div>
</div>
<include file="Include:javascript" />
<script src="__PUBLIC__/mobile/js/dropload.min.js"></script>
<script>
    var center_id = "{$center_id}";
    $(".project_menu,.search_btn_box a,.search_list_box a,.back_btn").click(function(){sessionStorage.clear();});
    //搜索
    $('.project_search').click(function(){
        $('.search_fix').fadeIn();
        $('html').addClass('active');
    })
	//新增
	$(".add_btn_new").click(function (){
        location.href="__APP__/Mobile/Crm/project_add"
	});
	//返回按钮
    $('.back_btn').click(function(){
        $('.search_fix').fadeOut();
        $('html').removeClass('active');
    })
    $('.jd_up').click(function(){
        sessionStorage.clear();
        var val = $('.project_search_inp').val();
        location.href="__APP__/Mobile/Crm/project_list/keyword/"+val;
    })
    $('.clear').click(function(){
        $.ajax({
            type: 'POST',
            async:false,
            dataType:"json",
            data:{"center_id":center_id},
            url:"__APP__/Mobile/Project/project_list_status",
            dataType: 'json',
            success: function(data){
                $('.search_list_box').html("<p style='padding:7px 0'>暂无相关内容</p>");
            }
        })
    })

    $(function(){
        var $now = 1;
        //输出本地存储now
        var $storage_now = sessionStorage.getItem("storage_now");
        if($storage_now){
            $now = parseInt($storage_now);
        }
        var page = 6,
            $count = "{$count}",
            max = Math.ceil(parseInt($count)/page);

        $('.content').dropload({
            scrollArea : window,
            loadDownFn : function(me){
                if($now<max){
                    var keyword = "{$keyword}",
						html = '',
                        $start_count = page*$now;
                    $.ajax({
                        type: 'POST',
                        async:false,
				        dataType:"json",
                        data:{"keyword":keyword,"start_size":$start_count,"start_page":page},
                        url:"__APP__/Mobile/Crm/project_list_ajax",
                        dataType: 'json',
                        success: function(data){
                            if(data){
                                for(var i=0; i<data.length; i++){
                                    html += '<li>';
										html += '<a href="__APP__/Mobile/Crm/project_situation/id/'+data[i].project_id+'">';
										html += '<div class="time">'+data[i].project_num+'<span>|</span>'+data[i].add_date+'<span>|</span>'+data[i].stage+'</div>';
										html += '<div class="name">'+data[i].name+'</div>';
										html += '<div class="user"><span>项目负责人：'+data[i].leader+'</span></div>';
                                    html += '</a>';
                                    html += '</li>';
                                }
                            }
                            $now++;
                            //保存本地存储
                            var $get_str_after = sessionStorage.getItem("storage_str"),
                                $storage_str = "";

                            if($get_str_after){
                                $storage_str += $get_str_after.replace(/^\[|\]$/g,"")+",";
                            }
                            $storage_str += JSON.stringify(data).replace(/^\[|\]$/g,"");
                            $storage_str = "["+$storage_str+"]";
                            sessionStorage.setItem("storage_str",$storage_str);
                            sessionStorage.setItem("storage_now",$now);
                            $('.project_list ul').append(html);
                            me.resetload();
                        },
                        error: function(xhr, type){
                            <!-- alert('Ajax error!'); -->
                            // 即使加载出错，也得重置
                            me.resetload();
                        }
                    });
                }else{
                    me.lock();
                    me.noData();
                    me.resetload();
                }
            }
            
        });
        
    })
    $(window).scroll(function(){
        //保存滚动条位置
        var $storage_top = $(window).scrollTop();
        sessionStorage.setItem("storage_top",$storage_top);
    });
    $(function(){
        var $get_str_before = sessionStorage.getItem("storage_str"),
            $storage_top = sessionStorage.getItem("storage_top");

        if($get_str_before){
            var $data = JSON.parse($get_str_before),
                $html = "";
           
            for(var i=0;i<$data.length;i++){
                $html += '<li>';
				$html += '<a href="__APP__/Mobile/Crm/project_situation/id/'+$data[i].project_id+'">';
				$html += '<div class="time">'+$data[i].project_num+'<span>|</span>'+$data[i].add_date+'<span>|</span>'+$data[i].stage+'</div>';
				$html += '<div class="name">'+$data[i].name+'</div>';
				$html += '<div class="user"><span>项目负责人：'+$data[i].leader+'</span></div>';
				$html += '</a>';
				$html += '</li>';
            }
            $('.project_list ul').append($html);
        }

        if($storage_top){
            $(window).scrollTop($storage_top);
        }
    })
</script>
</body>
</html>